import { getOrderSearchAPI,postaddOderAPI,postselectOrderAPI,postOrderStateAPI,postDeleteOrderAPI,postUpdateOrderAPI} from "../../api/userinfo"
import{OrderStateParams,OrderDeleteParams,OrderParams} from"../../types/parmas"
const order = {
  state: {
    orderInfo: {
    }, //用户订单基本信息
  },

  mutations: {
    //保存订单基本信息
    SET_ORDERINFO(state: any, value: any) {
      state.orderInfo = value;
    },
  },

  actions: {
    //修改订单状态
    async SET_ORDERSTATE(content: any, param:OrderStateParams) {
    return new Promise(async (resolve, reject)=>{
      await postOrderStateAPI(param).then((res: any) =>{
      })
    })
    },
    //查询所有订单
    async SET_ORDERINFO(content: any, id:any) {
      return new Promise(async (resolve, reject)=>{
        await postselectOrderAPI().then((res: any) => {
          resolve(res.data);
          content.commit("SET_ORDERINFO", res.data)
        })
      })
      },
      //添加
    async SET_ADDORDER(content: any, param:any) {
      return new Promise(async (resolve)=>{
        await postaddOderAPI(param).then((res)=>{
            resolve(res.data)
        })
      })
      },
      //删除
      async SET_DELETEORDER(content: any, param:number){
        return new Promise(async (resolve)=>{
          await postDeleteOrderAPI({oid:param}).then((res)=>{
            resolve(res)
          })
        }
        )},
        //修改
        async SET_UPDATEORDER(content: any, param:OrderParams){
          return new Promise(async (resolve)=>{
            await postUpdateOrderAPI(param).then((res)=>{
              resolve(res)
            })
          }
          )},
}     
}
export default order;